home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / rep504.arc / REPLACE.DOC < prev   
Text File  |  1991-04-16  |  18KB  |  537 lines

  1. ================================================================
  2. | REPLACE Version 5.04 1987-91 (C) Gene Garapic Cleveland Ohio |
  3. ================================================================
  4.   Comes AS-IS with no warranty  -  May be freely distributed
  5.  
  6. =========================
  7. | What does REPLACE do? |
  8. =========================
  9.   REPLACE searches a file for a specified string and if found replaces it
  10.   with another specified string continuing until the whole file is processed
  11.  
  12. =========================
  13. | Special Features      |
  14. =========================
  15.   Run REPLACE many times in a batch file using different parameters to get
  16.   almost any desired result.  See advanced user switches (Detail 2)
  17.  
  18. =========================
  19. | Getting Started       |
  20. =========================
  21.   Use MS DOS 2.00 up
  22.  
  23.   See Detail 1  
  24.   
  25.   Run REPLACE [filename] [find] [replace]
  26.  
  27.   Hint: Run REPLACE without parameters to display brief instruction set
  28.  
  29. =========================
  30. | Detail 1.0  Set PATH  |
  31. =========================
  32.   Set PATH so REPLACE can be found from any subdirectory
  33.  
  34.   Here is an example of a set PATH command line in your AUTOEXEC.BAT file
  35.   PATH=C:\DOSFILES;C:\GENE
  36.  
  37.   Replace.com, Replace.doc and Repxxx.zip would be in subdirectory GENE
  38.  
  39. ================================================
  40. | Detail 1.1  REPLACE.COM command line syntax  |
  41. ================================================
  42.   The normal DOS command line syntax is:
  43. REPLACE [filename] [find] [replace]
  44.  
  45.   Examples:
  46. REPLACE [filename] 13,10 13,10,13,10   <-Double space all single spaced lines
  47. REPLACE [filename] 13,10,13,10 13,10   <-Single space all double spaced lines
  48. REPLACE [filename] 13,10 13,10,9,9     <-Tab all lines twice for hole punch
  49. REPLACE [filename] "hello" "goodby"    <-Find hello replace with goodby
  50. REPLACE [filename] "hello" ""          <-Find hello and delete with null ("")
  51.  
  52.   Find string can not be null (""), replace string can
  53.   Comma (,) delimits decimal (0-255) ASCII codes
  54.   Quotation mark (") delimits ASCII character strings
  55.  
  56.   The orginal file is renamed with a BAK extension
  57.   The new file takes on the name of the original file
  58.  
  59.   Returns to the DOS command line prompt when done
  60.  
  61.   Tech Notes: 13 decimal equals a carriage return
  62.               10 decimal equals a line feed
  63.                9 decimal equals a tab  
  64.  
  65. ========================================================
  66. | Detail 2.0  Special advanced user function switches  |
  67. ========================================================
  68.   You should be able to find uses for some of these switches
  69.   Please try these switches on small test (junk) files first
  70.  
  71.   Detail 2.1.1  /F    Makes file of lines containing [string]
  72.   Detail 2.1.2  /F-   Makes file of lines NOT containing [string] (new 1991)
  73.   Detail 2.2    /P    Pad with spaces from code 1 to [column]
  74.   Detail 2.3    /C    Cut between columns [c1] [c2] inclusive
  75.   Detail 2.4    /E    Expand tabs in [file1] with spaces to [file2]
  76.   Detail 2.5    /R    Return key press upper case decimal errorlevel
  77.   Detail 2.6    /A    Act on column with wildcards (?) allowed
  78.   Detail 2.7    /N    Number all lines in an ASCII text file
  79.   Detail 2.8    /M    Return month to batch file as errorlevel (1-12)
  80.  
  81.   Note: Use only one switch at a time for each REPLACE run
  82.  
  83. ============================
  84. | Detail 2.1.1  /F switch  |
  85. ============================
  86. REPLACE [filename] [string] /F 
  87.   Makes a file of only the lines containing [string]
  88.   This function is something like your FIND.EXE DOS utility
  89.   
  90.   Example:
  91. Below is portion of REPLACE.ASM file before action:
  92. ----------------------------------------------
  93.   PAGE ,132
  94.   TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
  95.   CODE SEGMENT
  96.   ASSUME  CS:CODE,SS:CODE
  97.   ASSUME  DS:CODE,ES:CODE     
  98.   ORG  100H
  99.  
  100. REPLACE REPLACE.ASM "ASSUME" /F
  101.   Note: Above line was keyed in on DOS command line to start action
  102.  
  103. Below is REPLACE.ASM file after action:
  104. ---------------------------------------------
  105.   ASSUME  CS:CODE,SS:CODE
  106.   ASSUME  DS:CODE,ES:CODE     
  107.  
  108.   Note: Only lines containing ASSUME are now in REPLACE.ASM file
  109.  
  110. =============================
  111. | Detail 2.1.2  /F- switch  |
  112. =============================
  113. REPLACE [filename] [string] /F-
  114.   Makes a file of only the lines NOT containing [string]
  115.   This function is something like your FIND.EXE DOS utility
  116.   
  117.   Example:
  118. Below is portion of REPLACE.ASM file before action:
  119. ----------------------------------------------
  120.   PAGE ,132
  121.   TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
  122.   CODE SEGMENT
  123.   ASSUME  CS:CODE,SS:CODE
  124.   ASSUME  DS:CODE,ES:CODE     
  125.   ORG  100H
  126.  
  127. REPLACE REPLACE.ASM "ASSUME" /F-
  128.   Note: Above line was keyed in on DOS command line to start action
  129.  
  130. Below is REPLACE.ASM file after action:
  131. ---------------------------------------------
  132.   PAGE ,132
  133.   TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
  134.   CODE SEGMENT
  135.   ORG  100H
  136.  
  137.   Note: Only lines NOT containing ASSUME are now in REPLACE.ASM file
  138.  
  139. ==========================
  140. | Detail 2.2  /P switch  |
  141. ==========================
  142. REPLACE [filename] 1 "" /P[column]
  143.   Pads lines with spaces from code 1 to specified [column]
  144.  
  145.   Note: First run REPLACE to insert the 1 code
  146.         Then  run REPLACE with the /P switch
  147.  
  148.   Example:
  149. Below is portion of REPLACE.ASM file before action:
  150. ----------------------------------------------
  151.   PAGE ,132
  152.   TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
  153.   CODE SEGMENT
  154.   ASSUME  CS:CODE,SS:CODE
  155.   ASSUME  DS:CODE,ES:CODE     
  156.   ORG  100H
  157. START:  JMP     BEGIN       ; 
  158. OUT_PTR         DW        0  ; Used by all
  159. PAD_FLAG        DB        0   ; Pad function
  160. CUT_FLAG        DB        0     ; Cut between columns
  161. ERR_FLAG        DB        0    ; Return with error function
  162. EXP_FLAG        DB        0   ; Expand Tabs with Spaces
  163.  
  164.   Note: Semicolons (;) in lines do not line up
  165.   
  166. REPLACE REPLACE.ASM ";" 1,";"
  167.   Note: Above line was keyed in on DOS command line to start action
  168.         REPLACE is NOT using any special switches yet
  169.   
  170. Below is portion of REPLACE.ASM file after action:
  171. ---------------------------------------------
  172.   PAGE ,132
  173.   TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
  174.   CODE SEGMENT
  175.   ASSUME  CS:CODE,SS:CODE
  176.   ASSUME  DS:CODE,ES:CODE     
  177.   ORG  100H
  178. START:  JMP     BEGIN       ; 
  179. OUT_PTR         DW        0  ; Used by all
  180. PAD_FLAG        DB        0   ; Pad function
  181. CUT_FLAG        DB        0     ; Cut between columns
  182. ERR_FLAG        DB        0    ; Return with error function
  183. EXP_FLAG        DB        0   ; Expand Tabs with Spaces
  184.  
  185.   Note: 1 code displays as a  character
  186.   
  187.   Note: Now use /P switch to complete the job
  188.   
  189.   Example continued:
  190.  
  191. REPLACE REPLACE.ASM 1 "" /P37
  192.   Note: Above line was keyed in on DOS command line to start action
  193.  
  194. Below is portion of REPLACE.ASM file after action:
  195. ---------------------------------------------
  196.   PAGE ,132
  197.   TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
  198.   CODE SEGMENT
  199.   ASSUME  CS:CODE,SS:CODE
  200.   ASSUME  DS:CODE,ES:CODE     
  201.   ORG  100H
  202. START:  JMP     BEGIN               ; 
  203. OUT_PTR         DW        0         ; Used by all
  204. PAD_FLAG        DB        0         ; Pad function
  205. CUT_FLAG        DB        0         ; Cut between columns
  206. ERR_FLAG        DB        0         ; Return with error function
  207. EXP_FLAG        DB        0         ; Expand Tabs with Spaces
  208.  
  209.   Note: All the semicolons (;) now line up at column 37
  210.   
  211.   Note: Pads all 1 coded lines but only one 1 code () left indexed per run.
  212.         In other words if there are three 1 codes () per line then REPLACE
  213.         with /P switch must be run three times to complete job.  To find out
  214.         how many times to run REPLACE with the /P switch look at ASCII text
  215.         and count the 1 codes ( face characters) in one line
  216.         
  217.   Note: If 1 code is at line column greater then [column] then no action taken
  218.  
  219.   Note: If you use the /P switch you are a VERY advanced user!
  220.   
  221. ==========================
  222. | Detail 2.3  /C switch  |
  223. ==========================
  224. REPLACE [filename] [c1] [c2] /C
  225.   Cuts text from all lines in [filename] between columns [c1] [c2] inclusive
  226.  
  227.   Example:
  228. Below is portion of REPLACE.ASM file before action:
  229. ----------------------------------------------
  230.   PAGE ,132
  231.   TITLE REPLACE Version 2.08.22 1987-88 (C) Gene Garapic (1:157/502)
  232.   CODE SEGMENT
  233.   ASSUME  CS:CODE,SS:CODE
  234.   ASSUME  DS:CODE,ES:CODE     
  235.   ORG  100H
  236. START:  JMP     BEGIN               ; 
  237. OUT_PTR         DW        0         ; Used by all
  238. PAD_FLAG        DB        0         ; Pad function
  239. CUT_FLAG        DB        0         ; Cut between columns
  240. ERR_FLAG        DB        0         ; Return with error function
  241. EXP_FLAG        DB        0         ; Expand Tabs with Spaces
  242.  
  243.   Note: That there is text past column 37 on most lines
  244.  
  245. REPLACE REPLACE.ASM 37 80 /C
  246.   Note: Above was keyed in on DOS command to start action
  247.   
  248. Below is portion of REPLACE.ASM file after action:
  249. ---------------------------------------------
  250.   PAGE ,132
  251.   TITLE REPLACE Version 2.08.22 1987
  252.   CODE SEGMENT
  253.   ASSUME  CS:CODE,SS:CODE
  254.   ASSUME  DS:CODE,ES:CODE     
  255.   ORG  100H
  256. START:  JMP     BEGIN               
  257. OUT_PTR         DW        0         
  258. PAD_FLAG        DB        0         
  259. CUT_FLAG        DB        0         
  260. ERR_FLAG        DB        0         
  261. EXP_FLAG        DB        0         
  262.   
  263.   Note: Everything from column 37 thru 80 has been deleted (Cut) from file
  264.   
  265. ==========================
  266. | Detail 2.4  /E switch  |
  267. ==========================
  268. REPLACE [file1] /E >[file2]
  269.   Expand Tabs in [file1] with Spaces to [file2]
  270.  
  271.   Reason for using /E is that it makes ASCII files SORT.EXE compatible.
  272.   When sorting on columns SORT is fooled by files with tabs and does not
  273.   give proper results.  /E puts in spaces to the proper column when it
  274.   encounters tab (9) code making the file columns true as far as SORT is
  275.   concerned.  You will use SORT on the new file [file2]
  276.  
  277.   Example:
  278. REPLACE REPLACE.ASM /E >REPLACE2.ASM
  279.   Note: Above line was keyed in at the DOS prompt
  280.         There is disk activity but no screen action
  281.         Returns to DOS prompt when done
  282.  
  283.   An ASCII editor verifies REPLACE2.ASM file has spaces instead of tabs
  284.  
  285. ==========================
  286. | Detail 2.5  /R switch  |
  287. ==========================
  288. REPLACE /R
  289.   Returns user alpha key press in upper case decimal as error code
  290.   for batch file processing
  291.  
  292.   Example 1:
  293. REPLACE /R
  294.   Waits for a key press.
  295.   If "A" or "a" is pressed then decimal 65 (A) is returned to
  296.   your batch file as an error code for your batch file to process
  297.   
  298.   Example 2:
  299. REPLACE /R
  300.   Waits for a key press.
  301.   If "Z" or "z" is pressed then decimal 90 (Z) is returned to
  302.   your batch file as an error code for your batch file to process
  303.   
  304.   Note: Letters in between return their unique upper case code
  305.   
  306.   Note: Cut and Paste below example to file RTEST.BAT for demo
  307.  
  308. echo off
  309. cls
  310. echo        This is a demo using the REPLACE /R switch in a batch file
  311. echo   .
  312. :MENU
  313. echo   ====================================================================
  314. echo                                   MENU
  315. echo                         Press key for [function]
  316. echo   .
  317. echo   A [function]  B [function]  C [function]  D [function]  E [function]
  318. echo   F [function]  G [function]  H [function]  I [function]  J [function]
  319. echo   .
  320. echo                     Press Esc key to exit RTEST demo
  321. echo   .
  322. echo   Also try keys not shown in menu
  323. echo   Wait a few seconds for batch file to respond
  324. echo   ====================================================================
  325. REPLACE /R  Loads to get key press then returns to this batch file below
  326. rem         Highest errorlevel always tested first by DOS batch processor
  327. rem           90 (Z or z) is highest legal key press in this example
  328. if errorlevel 91 goto GREATER
  329. if errorlevel 75 goto NOFUNCT
  330. if errorlevel 74 goto J
  331. if errorlevel 73 goto I
  332. if errorlevel 72 goto H
  333. if errorlevel 71 goto G
  334. if errorlevel 70 goto F
  335. if errorlevel 69 goto E
  336. if errorlevel 68 goto D
  337. if errorlevel 67 goto C
  338. if errorlevel 66 goto B
  339. if errorlevel 65 goto A
  340. if errorlevel 28 goto LESS
  341. if errorlevel 27 goto ESC    Only legal key press below 65 in RTEST demo
  342. if errorlevel  1 goto LESS
  343. if errorlevel  0 goto ABORT
  344. :A
  345. echo   "A" or "a" was pressed so do it's [function] here
  346. goto   MENU
  347. :B
  348. echo   "B" or "b" was pressed so do it's [function] here
  349. goto   MENU
  350. :C
  351. echo   "C" or "c" was pressed so do it's [function] here
  352. goto   MENU
  353. :D
  354. echo   "D" or "d" was pressed so do it's [function] here
  355. goto   MENU
  356. :E
  357. echo   "E" or "e" was pressed so do it's [function] here
  358. goto   MENU
  359. :F
  360. echo   "F" or "f" was pressed so do it's [function] here
  361. goto   MENU
  362. :G
  363. echo   "G" or "g" was pressed so do it's [function] here
  364. goto   MENU
  365. :H
  366. echo   "H" or "h" was pressed so do it's [function] here
  367. goto   MENU
  368. :I
  369. echo   "I" or "i" was pressed so do it's [function] here
  370. goto   MENU
  371. :J
  372. echo   "J" or "j" was pressed so do it's [function] here
  373. goto   MENU
  374. :NOFUNCT
  375. echo   Errorlevel 75 through 90 has no [function] assigned in RTEST demo
  376. goto   MENU
  377. :GREATER
  378. echo   Errorlevel greater then 90 decimal is not legal in RTEST demo
  379. goto   MENU
  380. :LESS
  381. echo   Errorlevel less then 65 decimal is not legal in RTEST demo
  382. goto   MENU
  383. :ABORT
  384. echo   .
  385. echo   Errorlevel is 0 so aborting    
  386. echo   .
  387. echo   Possible cause is REPLACE.COM missing
  388. goto end
  389. :ESC
  390. echo   .
  391. echo   Esc key was pressed   
  392. :end
  393.  
  394. ==========================
  395. | Detail 2.6  /A switch. |
  396. ==========================
  397.   Note: Wildcards are allowed when using the /A switch
  398.  
  399. REPLACE [filename] [find?] [replace] /A[column]
  400.   Find and replace at [column] with wildcards (?) allowed in [find] string
  401.  
  402.   Example of /A switch with a file named TEST.TXT
  403.  
  404.   Before action
  405. REPLACE  ASM    53695   8-22-88   7:56a
  406. R-TUP    BAT      167   8-22-88   9:14a
  407. REPLACE  COM     4593   8-22-88   7:57a
  408. REPLACE  DOC    16109   8-22-88   9:13a
  409.  
  410. REPLACE TEST.TXT "-??" "-90" /A29
  411.   Note: Above keyed in on DOS command line
  412.  
  413.   After action
  414. REPLACE  ASM    53695   8-22-90   7:56a
  415. R-TUP    BAT      167   8-22-90   9:14a
  416. REPLACE  COM     4593   8-22-90   7:57a
  417. REPLACE  DOC    16109   8-22-90   9:13a
  418.   Note: ---- Column 29 ---->^
  419.  
  420.   Note: "-??" would include "-22" in find string but "-22" starts before
  421.         column 29 therefore is not effected by replace string and only
  422.         "-88" is replaced with "-90" in each line
  423.  
  424.   Note: Wildcards need not be used with /A switch
  425.  
  426.   Note: /A with no [column] starts action at beginning of line and does
  427.         the complete line instead of just at the specified column
  428.  
  429.   Note: If you use the /A switch you are a VERY advanced user!
  430.  
  431. ==========================
  432. | Detail 2.7  /N switch  |
  433. ==========================
  434. REPLACE [filename] /N
  435.   Number all lines in an ASCII text file 
  436.   Text file lines must be terminated with Carriage Return and Line Feed
  437.  
  438.   Example of /N switch with a file named LN.ASM
  439.  
  440.   Selected portion before action
  441. ;---------------------------------------;
  442.   PAGE ,132                             ;
  443.   VER   EQU     '  Version 1.07.01 '    ;
  444.   CODE SEGMENT                          ;
  445.   ASSUME        CS:CODE,SS:CODE         ;
  446.   ASSUME        DS:CODE,ES:CODE         ; 
  447.   ORG   100H                            ;
  448. ;---------------------------------------;
  449. START:  JMP     DO_LINE_NUMBER          ; 
  450.  
  451. REPLACE LN.ASM /N
  452.   Note: Above keyed in DOS command line
  453.  
  454.   Selected portion after action
  455.     1  ;---------------------------------------;
  456.     2    PAGE ,132                             ;
  457.     3    VER   EQU     '  Version 1.07.01 '    ;
  458.     4    CODE SEGMENT                          ;
  459.     5    ASSUME        CS:CODE,SS:CODE         ;
  460.     6    ASSUME        DS:CODE,ES:CODE         ; 
  461.     7    ORG   100H                            ;
  462.     8  ;---------------------------------------;
  463.     9  START:  JMP     DO_LINE_NUMBER          ; 
  464.  
  465. ==========================
  466. | Detail 2.8  /M switch  |
  467. ==========================
  468. REPLACE /M
  469.   Return month to batch file as errorlevel (1-12)
  470.  
  471.   Below is a demo batch file named M.BAT
  472.  
  473. echo off
  474. cls
  475. REPLACE /M
  476. if errorlevel 12 goto DEC
  477. if errorlevel 11 goto NOV
  478. if errorlevel 10 goto OCT
  479. if errorlevel  9 goto SEP
  480. if errorlevel  8 goto AUG
  481. if errorlevel  7 goto JUL
  482. if errorlevel  6 goto JUN
  483. if errorlevel  5 goto MAY
  484. if errorlevel  4 goto APR
  485. if errorlevel  3 goto MAR
  486. if errorlevel  2 goto FEB
  487. if errorlevel  1 goto JAN
  488. :DEC
  489. echo December
  490. goto endM
  491. :NOV
  492. echo November
  493. goto endM
  494. :OCT
  495. echo October
  496. goto endM
  497. :SEP
  498. echo September
  499. goto endM
  500. :AUG
  501. echo August
  502. goto endM
  503. :JUL
  504. echo July
  505. goto endM
  506. :JUN
  507. echo June
  508. goto endM
  509. :MAY
  510. echo May
  511. goto endM
  512. :APR
  513. echo April
  514. goto endM
  515. :MAR
  516. echo March
  517. goto endM
  518. :FEB
  519. echo February
  520. goto endM
  521. :JAN
  522. echo January
  523. :endM
  524.  
  525.   Note: You must have Clock/Calendar or set DATE for accurate result
  526.  
  527. ===========================
  528. | Detail 3.0  Uploading   |
  529. ===========================
  530.   If uploading Rep504.zip to BBSes please use comment line as shown below
  531.  
  532. Garapic's search and replace plus
  533.  
  534. ====================
  535. | End REPLACE.DOC  |
  536. ====================
  537.